<template>
	<view :class="isDark?'darkBg':''">
		<cu-custom :bgColor="isDark?'bg-black':'bg-blue'" isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">信息填报</block>
		</cu-custom>
		<!-- 	<view style="height: 545rpx; background-size: cover;  background-position: center;"
			:style="{backgroundImage:isDark?'url(https://web.cloudduolc.cn/image/adblack7.png)':'url(https://web.cloudduolc.cn/image/adwhite5.png)'}">
			<ad unit-id="adunit-8f5833c88a4b6a95" ad-type="video" :ad-theme="isDark?'black':'white'"></ad>
		</view> -->
		<view class="container" :class="isDark?'dark':'bg-white'">


			<view class="cu-bar  solid-bottom" style="font-weight:bold" :class="isDark?'dark':'bg-white'">
				<view class="action">
					<text class="cuIcon-titles text-blue"></text>信息填报
					<text class="cuIcon-search"></text>

				</view>

			</view>
			<view class="cu-form-group margin-top">
				<view>每天早上8点提醒</view>
				<button class="cu-btn round line margin-left-xl " :class="isDark?'dark':''"
					@click="subscribe()">订阅填报提醒</button>
			</view>
			<view class="cu-form-group margin-top">
				<view class="title">自动填报</view>
				<switch @change="AutoState" :class="autoState?'checked':''" :checked="autoState?true:false"></switch>
			</view>
			<view class="cu-form-group margin-top">
				<view class="title">是否要将订阅按钮与课表入口绑定（点击【我的课表】按钮即可订阅）</view>
				<switch @change="TimeState" :class="timeState?'checked':''" :checked="timeState?true:false"></switch>
			</view>
		</view>
		<zmm-watermark>

		</zmm-watermark>
	</view>
</template>

<script>
	export default {

		data() {
			return {
				isDark: this.isDark,
				pay: false,
				timeState: false,
				auto: false,
			}
		},
		onShow() {
			let _this = this

			//#ifdef H5
			this.pay = true
			//#endif
			_this.timeState = _this.$store.state.timeRemind
		},
		methods: {
			TimeState(e) {
				this.timeState = e.detail.value
				this.$store.commit("timeRemind", this.timeState)

			},
			AutoState(e) {
				this.autoState = e.detail.value
				if (e.detail.value == true) {
					uni.showToast({
						title: '不要做梦，自己好好打卡',
						icon: 'none'
					})
				}
			},
			subscribe() {
				let _this = this
				wx.requestSubscribeMessage({
					tmplIds: ['4ZKFi9k82DZccLcasP7Td-TRBtKDUc2onbWQ3f7sfwQ'],
					success(res) {
						console.log(res)
						if (res['4ZKFi9k82DZccLcasP7Td-TRBtKDUc2onbWQ3f7sfwQ'] == 'accept') {
							_this.$schoolApi.healthAddRemind(null).then(function(response) {
								console.log(response)
								if (response.status == 0) {
									uni.showToast({
										title: '订阅一次成功，可累加',
										icon: 'none'
									})

								} else if (response.status != 608 && response.status != 603) {
									uni.showModal({
										title: '提示',
										content: response.msg,
										showCancel: false,
										success: function(res) {
											if (res.confirm) {

											} else if (res.cancel) {

											}
										}
									});
								}

								//这里只会在接口是成功状态返回
							}).catch(function(error) {
								//这里只会在接口是失败状态返回，不需要去处理错误提示
								console.log(error);
							});
						} else {
							uni.showToast({
								title: '取消订阅',
								icon: 'none'
							})
						}

					},
					fail(res) {
						console.log(res)
						uni.showToast({
							title: '订阅失败',
							icon: 'none'
						})
					}
				})

			},
		}
	}
</script>

<style>
	.container {
		padding: 20px;
		font-size: 14px;
		line-height: 24px;
		font-family: 'Courier New', Courier, monospace;
	}

	.smallButton {
		width: 400rpx;
		background-color: #428bca;
		border-color: #357ebd;
		color: #fff;
		-moz-border-radius: 10rpx;
		-webkit-border-radius: 10rpx;
		border-radius: 10rpx;
		/* future proofing */
		-khtml-border-radius: 10rpx;
		/* for old Konqueror browsers */
		text-align: center;
		border: 1rpx solid transparent;
		margin: 0 rpx auto;
		font-size: 37rpx;
		height: 100rpx;
		line-height: 100rpx;
		margin-top: 20rpx;
	}
</style>
